<template>
  <!--毕业设计相关打印-->
  <div class="edu-page-warp">
    <!--新增弹框-->
    <DesignPrintDialog ref="designPrintDialog" :dialogVisible="dialogVisible" :actionType="actionType" :designPrintForm="designPrintForm" @design-print-submit="onSubmit" @design-print-cancel="onCancel" v-if="dialogVisible"></DesignPrintDialog>

    <el-card shadow="never">
      <div class="edu-page-title">{{$t('graduationDesign.graduationDesignPrint')}}</div>
      <div class="edu-opertion-bar">
        <div class="float-right">
          <el-button type="primary" @click="onAdd" v-premit="design_print_add">{{$t('graduationDesign.add')}}</el-button>
        </div>
      </div>
      <edu-table ref="graduationDesignPrintTable" :url="getList" :selection="false">
        <edu-table-column :label="$t('graduationDesign.graduationDesignRelatedForm')" prop="attachName" min-width="150">
          <template slot-scope="scope">
            <el-button type="text" @click="onDownload(scope.row)">{{scope.row.attachName}}</el-button>
          </template>
        </edu-table-column>
        <edu-table-column :label="$t('graduationDesign.operation')" min-width="120">
          <template slot-scope="scope">
            <el-button type="text" @click="onEdit(scope.row)" v-premit="design_print_edit">{{$t('graduationDesign.edit')}}</el-button>
            <el-button type="text" @click="onDelete(scope.row)" v-premit="design_print_delete">{{$t('graduationDesign.delete')}}</el-button>
          </template>
        </edu-table-column>
      </edu-table>
    </el-card>
  </div>
</template>
<script>
import API from "common/src/api/underGraduationDesign/graduationDesign";
import tools from 'common/src/views/underGraduationDesign/tools.js';
export default {
  name: 'graduationDesignPrint',
  data() {
    return {
      api: API,
      getList: '/api/designservice/docRelatedPrint/queryByPage',
      queryForm: {},
      actionType: 'ADD',
      loading: false,
      dialogVisible: false,
      designPrintForm: {},
    };
  },
  mounted() {
    this.searchList();
  },
  methods: {
    searchList() {
      this.$refs.graduationDesignPrintTable.search(this.queryForm);
    },
    onDownload(row) {
      // window.location.href = "/api/commonservice/obsfile/downloadfile?objectkey=" + row.attachPath;
      tools.doDownload(row.attachPath, row.attachName);
    },
    onAdd() {
      this.actionType = "ADD";
      this.dialogVisible = true;
      this.designPrintForm = {
        attachName: '',
        attachPath: ''
      };
    },
    onEdit(row) {
      this.actionType = "EDIT";
      this.dialogVisible = true;
      this.designPrintForm = { ...row };
    },
    onSubmit(data, action) {
      let reqApi = null;
      if (action === "ADD") {
        reqApi = this.api.printSave(data);
      } else {
        reqApi = this.api.printUpdate(data);
      }
      reqApi.then(res => {
        this.$message.success(action === "ADD" ? this.$t('graduationDesign.addSuccess') : this.$t('graduationDesign.modifySuccess'));
        this.indexKey = "MAIN";
        this.dialogVisible = false;
        this.searchList();
      }).catch(() => { });
    },
    onCancel() {
      this.dialogVisible = false;
    },
    onDelete(row) {
      this.$delConfirm(this.$t('graduationDesign.deleteConfirm'), this.$t('graduationDesign.delete')).then(res => {
        const params = { id: row.id };
        this.api.printDelete(params).then(res => {
          this.$message.success(this.$t('graduationDesign.deleteSuccess'));
          this.searchList();
        });
      }).catch(() => { });
    }
  },
  components: {
    DesignPrintDialog: () => import('../components/designPrintDialog')
  }
}
</script>
<style lang="scss" scoped>
</style>
